package cn.yer.dao;

import cn.yer.util.ConnectionFactory;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

public class ZmglDao {


    public JSONObject zmtj(String khxm){
        Connection conn=null;
        Statement stmt=null;
        ResultSet rs=null;
        JSONObject rtObj=new JSONObject(),resObj=null;
        JSONArray jsonArr=new JSONArray();
        rtObj.put("FLAG",1);
        rtObj.put("DATA",jsonArr);
        String sql="select khxm,sum(if(jg='',1,0)) wjs,sum(if(jg!='',1,0)) yjs,sum(jg) je from hwysmxb t where djr='"+khxm+"' GROUP BY khxm";
        System.out.println(sql);
        try {
            conn=ConnectionFactory.getConnection();
            stmt=conn.createStatement();
            rs=stmt.executeQuery(sql);
            while (rs.next()){
                resObj=new JSONObject();
                resObj.put("khxm",rs.getString("khxm"));
                resObj.put("wjs",rs.getString("wjs"));
                resObj.put("yjs",rs.getString("yjs"));
                resObj.put("je",rs.getString("je"));
                jsonArr.add(resObj);
            }

            rtObj.put("DATA",jsonArr);
        }catch (Exception e){
            rtObj.put("",0);
        }finally {
            ConnectionFactory.closeAll(rs,stmt,conn);
        }

        return rtObj;
    }
}
